#include <cstdio>  
#include <queue>  
using namespace std;  
int main()
{

    int n;
	priority_queue<int,vector<int>,greater<int> > qu;  
	scanf("%d",&n);
    while(n--)
	{
		int x;  
		scanf("%d",&x); 
		qu.push(x);  
	}
	int a=0,b=0;  
	long long res=0;  
	while(1)
	{
		a=qu.top();  
		qu.pop();  
		if(qu.empty())break;  
		b=qu.top();  
		qu.pop();  
		res+=a+b;  
		qu.push(a+b) ;  
    }   
    printf("%lld\n",res);         
    return 0;  
}   
